package com.gaff.emp.core.syslog.event;

import com.gaff.emp.core.modules.sys.dao.SysLogDao;
import com.gaff.emp.core.modules.sys.entity.SysLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class SysLogListener {

    @Autowired
    private SysLogDao sysLogDao;

    @Async
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent event) {
        SysLog sysLog = (SysLog) event.getSource();
        log.info("{}", sysLog);
        if (sysLog.isPersistence()) {
            sysLogDao.insert(sysLog);
        }
    }

}
